//
//  main.m
//  选择排序
//
//  Created by 陶建 on 2017/7/20.
//  Copyright © 2017年 taoJ. All rights reserved.
//

#import <Foundation/Foundation.h>
void xuanze();
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        int a[] = {3,31,12,23,5,11,7,2,4,6,8,0,21,34,1321,1};
        
        int tmp, btmp;
        for (int i = 0; i < sizeof(a)/ sizeof(1)-1; i++) {
            tmp = i;
            // 找到最小值的索引
            for (int j = i+1; j <sizeof(a)/ sizeof(1); j++) {
                if (a[tmp] > a[j]) tmp = j;
            }
            
            if (tmp == i) continue;
            // 最小值与i互换, 这样就形成了前面有序, 后面无序
            btmp = a[tmp];
            a[tmp] = a[i];
            a[i] = btmp;
        }
        
        for (int i = 0; i < sizeof(a)/ sizeof(1); i++) {
            printf("%d\n", a[i]);
        }
    }
    return 0;
}

void xuanze() {
    
}
